package com.lebang.controller.api;

import com.lebang.aop.Sessionid;
import com.lebang.common.Require;
import com.lebang.entity.LbbDict;
import com.lebang.entity.LbbFloatSwitch;
import com.lebang.service.buss.AppFloatSwitchService;
import com.lebang.service.sys.DictService;
import com.lebangweb.response.Callback;
import com.lebangweb.response.JsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * 临时接口
 *
 * @author weizx
 * @className Api
 * @date 2018年8月27日 上午9:47:42
 */
@RestController
public class Api {


    @Autowired
    private DictService dictService;


    @Autowired
    private AppFloatSwitchService appFloatSwitchService;




    /**
     * 支付宝口令红包
     *
     * @param request
     * @param response
     * @return
     */
    @Require
    @Sessionid
    @RequestMapping(value = {"/zfb/token"}, method = {RequestMethod.GET, RequestMethod.POST})
    public JsonData token(HttpServletRequest request, HttpServletResponse response) {
        LbbDict dict = dictService.selectByKeyName("zfb_token");
        return Callback.success("success", "", dict != null ? dict.getKeyvalue() : null);
    }






    @RequestMapping(value = {"/float/data"}, method = {RequestMethod.GET})
    public JsonData floatSwitch(HttpServletRequest request, HttpServletResponse response) {
        LbbFloatSwitch afs = appFloatSwitchService.getByCategory("floatSwitch");
        Map<String, Object> data = new LinkedHashMap<>();
        data.put("direction", afs.getDirection());
        data.put("exhibition", afs.getExhibition());
        data.put("url", afs.getUrl());
        data.put("picture", afs.getPicture());
        return Callback.success("success", "获取数据成功！", data);
    }

}
